package com.atom.process.cnmuseum.cj.dao.task;


import java.util.List;

import org.springframework.stereotype.Repository;

import com.atom.common.dao.AvensCommonDao;
import com.atom.common.exception.AvensNullPointerException;
import com.atom.common.remote.user.UserUtil;
import com.atom.process.cnmuseum.cj.entity.task.CjGcxxTaskDO;

@Repository
public class CjGcxxTaskDao extends AvensCommonDao<CjGcxxTaskDO> {

	public CjGcxxTaskDO findByTaskId(String taskId) {
	    List<CjGcxxTaskDO> list = super.findByProperty("taskId", taskId);
	    if (list == null || list.size() == 0) {
	      throw new AvensNullPointerException("TaskDO is null where taskId = " + taskId);
	    } else {
	      return list.get(0);
	    }
	  }
	
	public CjGcxxTaskDO findLastByProcessId(String taskId) {
	    List<CjGcxxTaskDO> list = super.findByPropertyOrderBy("processId", taskId, "id");
	    if (list == null || list.size() == 0) {
	      throw new AvensNullPointerException("TaskDO is null where taskId = " + taskId);
	    } else {
	      return list.get(list.size()-1);
	    }
	  }
  
  
  public Integer createADO(UserUtil user, String processInstanceId, String taskId) {
	  CjGcxxTaskDO ado = new CjGcxxTaskDO();
	    ado.setProcessId(processInstanceId);
	    ado.setTaskId(taskId);
	    save(ado);
	    return ado.getId();
	  }

}
